﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
@* <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head> *@
<body>

    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">
                <table>
                    <tr>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">销售日期</label>
                                <div class="layui-input-inline layui-input-wrap">
                                    <input type="date" id="sellTime" class="layui-input">
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">客户</label>
                                <div class="layui-input-block">
                                    <select id="clientId" lay-filter="testSelect">
                                        <option value="-1">请选择</option>
                                        <option value="0">黄赛超</option>
                                        <option value="1">李颖</option>
                                        <option value="2">崔海瑞</option>
                                    </select>
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">销售员</label>
                                <div class="layui-input-block">
                                    <select id="salesman" lay-filter="testSelect">
                                        <option value="">请选择</option>
                                        <option value="张三">张三</option>
                                        <option value="李四">李四</option>
                                        <option value="王五">王五</option>
                                    </select>
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">部门</label>
                                <div class="layui-input-block">
                                    <select id="departmentId" lay-filter="testSelect">
                                        <option value="-1">请选择</option>
                                        <option value="0">默认</option>
                                        <option value="1">销售部</option>
                                        <option value="2">人事部</option>
                                    </select>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">仓库</label>
                                <div class="layui-input-block">
                                    <select id="stash" lay-filter="testSelect">
                                        <option value="-1">请选择</option>
                                        <option value="一号仓">一号仓</option>
                                        <option value="二号仓">二号仓</option>
                                        <option value="三号仓">三号仓</option>
                                    </select>
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">收货地址</label>
                                <div class="layui-input-inline layui-input-wrap">
                                    <input type="text" id="deliveryAddress" class="layui-input">
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">单据号</label>
                                <div class="layui-input-inline layui-input-wrap">
                                    --
                                </div>
                            </div>
                        </td>
                        <td>
                            <div class="layui-inline">
                                <label class="layui-form-label">流水号</label>
                                <div class="layui-input-block">
                                    --
                                </div>
                            </div>
                        </td>
                    </tr>
                </table>
                <button type="button" class="layui-btn layui-bg-red" onclick="Add()" lay-on="test-iframe-curl">新增</button>

            </div>
        </div>


        <table class="layui-table" style="width:200%">
            <thead>
                <tr>
                    <td>耳号</td>
                    <td>成交价</td>
                    <td>定价（元）</td>
                    <td>折扣比例</td>
                    <td>等级</td>
                    <td>品种</td>
                    <td>性别</td>
                    <td>羊只类型</td>
                    <td>繁殖状态</td>
                    <td>栋舍</td>
                    <td>栏位</td>
                    <td>出生日期</td>
                    <td>出生重（kg）</td>
                    @* <td>断奶重（kg）</td> *@
                    <td>父号</td>
                    <td>母号</td>

                </tr>
            </thead>
            <tbody>
                <tr>
                    @* 耳号 *@
                    <td>
                        <select id="earBugles" lay-filter="testSelect">
                            <option value="">请选择</option>
                        </select>
                    </td>
                    @* 成交价 *@
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="closingPrice" class="layui-input">
                        </div>
                    </td>
                    @* 定价（元） *@
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="fixPrice" class="layui-input">
                        </div>
                    </td>
                    @* 折扣比例 *@
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="discount" class="layui-input">
                        </div>
                    </td>
                    @* 基因等级 *@
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="gene" class="layui-input">
                        </div>
                    </td>
                    @* 品种 *@
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="recordBreed" class="layui-input">
                        </div>
                    </td>
                    @* 性别 *@
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="sex" class="layui-input">
                        </div>
                    </td>
                    @* 羊只类型 *@
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="recordType" class="layui-input">
                        </div>
                    </td>
                    @* 繁殖状态 *@
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="reproductiveState" class="layui-input">
                        </div>
                    </td>
                    @* 栋舍 *@
                    <td> 
                        <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="cottageName" class="layui-input">
                        </div>
                    </td>
                   @*  栏位 *@
                    <td> 
                        <div class="layui-input-inline layui-input-wrap">
                        <input type="text" id="fieldName" class="layui-input">
                        </div>
                    </td>
                    @* 出生日期 *@
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="recordDate" class="layui-input">
                        </div>
                    </td>
                    @* 出生重（kg） *@
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="recordWeight" class="layui-input">
                        </div>
                    </td>
                    @* 断奶重（kg） *@
                 @*    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="weaning" class="layui-input">
                        </div>
                    </td> *@
                    @*父号 *@
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="recordFather" class="layui-input">
                        </div>
                    </td>
                    @*母号 *@
                    <td>
                        <div class="layui-input-inline layui-input-wrap">
                            <input type="text" id="recordMother" class="layui-input">
                        </div>
                    </td>

                </tr>
            </tbody>
        </table>


        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" id="remark"></textarea>
            </div>
        </div>


    </form>


    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>
    <script>
        layui.use('form', function () {
            var table = layui.table;
            var form = layui.form;
            var layer = layui.layer;
            //绑定耳号
            bangsheng1();
            //绑定栋舍
            bangsheng();

            FantearBugles();



            //获取耳号下拉框的值
            form.on('select(testSelect)', function (data) {
                FantearBugles(data.value); // data.value 返回选中的值
                console.log(data.value, 6666666666)
            });


            //绑定栋舍
            function bangsheng() {
                $.ajax({
                    url: "http://localhost:5123/api/Cottage/CottageSecondaryQuery",
                    data: JSON.stringify({}),
                    type: "post",
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res)
                        $.each(res.data, function () {
                            $("#cottageId").append(`<option value="${this.cottageId}">${this.cottageName}</option>`);
                        })
                        form.render('select'); // 重新渲染下拉框
                    }
                })
            }

            //获取栋舍下拉框的值
            form.on('select(provincet)', function (data) {
                provincetId1 = data.value;
                console.log(provincetId1, 15152)
                $("#field").empty();
                $("#field").append('<option value="">请选择</option>');
                bangshi()

            });

            //绑定栏位
            function bangshi() {
                var cottageId = $("#cottageId").val();
                $.ajax({
                    url: "http://localhost:5123/api/Field/GetFieldCottage",
                    data: JSON.stringify({ cottageId: cottageId }),
                    type: "post",
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res.data)

                        $.each(res.data, function () {
                            $("#field").append(`<option value="${this.fieldId}">${this.fieldName}</option>`);
                        })
                        form.render('select'); // 重新渲染下拉框
                    }

                })
            }

            //绑定耳号
            function bangsheng1() {

                $.ajax({
                    url: "http://localhost:5269/api/SheepArchive/SheepEarBuglesQuery",
                    data: JSON.stringify({}),
                    type: "post",
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res)
                        $.each(res.data, function () {
                            $("#earBugles").append(`<option value="${this.recordAuricle}">${this.recordAuricle}</option>`);
                        })
                        form.render('select'); // 重新渲染下拉框

                    }

                })
            }

            //根据耳号加载数据
            //var aa = "";
            function FantearBugles(aa) {
                //var recordAuricle = $("#earBugles").val();
                $.ajax({
                    url: 'http://localhost:5269/api/SheepArchive/SheepEarBuglesBackFill',
                    type: 'post',
                    data: JSON.stringify({ recordAuricle: aa }),
                    dataType: 'json',
                    contentType: 'application/json',
                    success: res => {
                        var aa = this.reproductiveState == 1 ? "后备空怀" : this.reproductiveState == 2 ? "返情空怀" : this.reproductiveState == 3 ? "未孕空怀" : this.reproductiveState == 4 ? "流产空怀" : this.reproductiveState == 5 ? "空胎空怀" : this.reproductiveState == 6 ? "断奶空怀" : this.reproductiveState == 7 ? "妊检" : "哺乳"
                        var bb = this.recordType == 0 ? "种母" : this.recordType == 1 ? "种公" : "后裔";
                        $(res.data).each(function () {
                            $("#gene").val(this.gene)
                            $("#recordBreed").val(this.recordBreed)
                            $("#sex").val(this.sex)
                            $("#recordType").val(bb)
                            $("#reproductiveState").val(aa)
                            $("#cottageName").val(this.cottageName)
                            $("#fieldName").val(this.fieldName)
                            $("#recordDate").val(this.recordDate)
                            $("#recordWeight").val(this.recordWeight)
                            $("#recordFather").val(this.recordFather)
                            $("#recordMother").val(this.recordMother)
                        })
                        console.log(res, 88888)
                    }
                })
            }

        })





        //养只销售新增
        function Add() {
            var data = {
                recordAuricle: $("#earBugles").val(),
                sellTime: $("#sellTime").val(),
                clientId: $("#clientId").val(),
                salesman: $("#salesman").val(),
                departmentId: $("#departmentId").val(),
                stash: $("#stash").val(),
                deliveryAddress: $("#deliveryAddress").val(),
                closingPrice: $("#closingPrice").val(),
                fixPrice: $("#fixPrice").val(),
                discount: $("#discount").val()
            }

            $.ajax({
                url: "http://localhost:5269/api/SheepSells/SheepSellCreate",
                type: 'post',
                data: JSON.stringify(data),
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    if (res.code == 0) {
                        layer.msg('添加成功')
                        location.href = "/Purchase/SellIndex"
                    }
                    else {
                        layer.msg('保存失败')
                    }
                }
            })
        }

    </script>


</body>

</html>